package com.devicemantra.coordinate.operations;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.devicemantra.coordinate.dataobjects.CStateFactory;
import com.devicemantra.coordinate.exceptions.dataobjects.CDatabaseException;
import com.devicemantra.coordinate.exceptions.jaxb.CJAXBException;
import com.devicemantra.coordinate.exceptions.operations.CException;
import com.devicemantra.coordinate.exceptions.operations.CReadPayloadException;
import com.devicemantra.coordinate.exceptions.operations.CStateAlreadyExistsException;
import com.devicemantra.coordinate.interfaces.http.CHttpReader;
import com.devicemantra.coordinate.jaxb.*;



public class CResponseBuilder 
{
	private Response mResponse = null;
	private ObjectFactory mJAXBObjectFactory = null;
	
	public CResponseBuilder()
	{
		mJAXBObjectFactory = new ObjectFactory();
		mResponse = mJAXBObjectFactory.createResponse();
		ResponseData lRespData = mJAXBObjectFactory.createResponseData();
		mResponse.setCResponseData(lRespData);
	}
	
	public void setStatus(int pRespCode, String pReason)
	{
		Status lStatus = mJAXBObjectFactory.createStatus();
		lStatus.setCRespCode(pRespCode);
		lStatus.setCReason(pReason);
		mResponse.getCResponseData().setCStatus(lStatus);
	}
	
	public String getAsXML() throws CException
	{
		String lXMLResponseStr = null;
		try {
			lXMLResponseStr = JAXBResponseFactory.createResponse(mResponse);
		} catch (CJAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new CException(e.getMessage());
		}
		return lXMLResponseStr;
	}
	
	
	
	
	
}
